<?php

namespace LowCode\Naive;

use LowCode\Naive;
use LowCode\Support\JsExp;
use LowCode\Traits\Props\HasDisabled;
use LowCode\Traits\Props\HasLabel;
use LowCode\Traits\Props\HasName;
use LowCode\Traits\Props\HasSize;

/**
 * Radio组件
 * @method static static make(string|JsExp $name, string|JsExp $label, string|int|bool|JsExp $value = null) Radio组件
 */
class Radio extends Naive
{

    use HasName, HasLabel, HasDisabled, HasSize;

    /**
     * @param string|int|bool|null $value
     */
    public function __construct(string|JsExp $name, string|JsExp $label, string|int|bool|JsExp $value = null)
    {
        parent::__construct();
        $this->name($name)->label($label)->value($value);
    }

    /**
     * 按钮
     * @return $this
     */
    public function button(): static
    {
        return $this->componentName("NRadioButton");
    }

    /**
     * 设置组件值
     * @param mixed $value
     * @return $this
     */
    public function value(string|int|bool|JsExp $value = null): static
    {
        return $this->prop('value', $value);
    }

    /**
     * 默认选中的状态
     * @param bool|JsExp $bool
     * @return $this
     */
    public function defaultChecked(bool|JsExp $bool = false): static
    {
        return $this->prop('default-checked', $bool);
    }

    /**
     * 选中状态
     * @param bool|JsExp $bool
     * @return $this
     */
    public function checked(bool|JsExp $bool = false): static
    {
        return $this->prop('checked', $bool);
    }

    /**
     * 选中状态
     * @param string $value
     * @param string|null $id
     * @param array $options
     * @return $this
     */
    public function vModelChecked(string $value, string $id = null, array $options = []): static
    {
        return $this->vModelArg("check", $value, $id, $options);
    }

    /**
     * 发生变化时触发的回调方法
     * @param string $event (value: boolean) => void
     * @param string|null $id
     * @param array $modifiers
     * @return $this
     */
    public function onUpdateChecked(string $event = "(value) => {}", string $id = null, array $modifiers = []): static
    {
        return $this->event('update:checked', jsFn($event,$id), $modifiers);
    }
}
